package com.encrypt;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 使用classfinal-maven-plugin插件加密java项目
 *
 * 1.准备测试接口
 *
 * 2.pom文件中引入插件
 *
 * 3.项目打包
 *
 * 4.为项目绑定机器码
 *
 * 5.解密项目，查看项目加密效果
 *
 */

@Slf4j
@SpringBootApplication
public class EncryptApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(EncryptApplication.class, args);
    }

    @Bean
    @Primary
    @ConditionalOnMissingBean(ObjectMapper.class)
    public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        return objectMapper;
    }
}
